This is Info file make.info, produced by Makeinfo-1.54 from the input file make.texinfo. This file documents the GNU Make utility, which determines automatically which pieces of a large program need to be recompiled, and issues the commands to recompile them. This is Edition 0.42, last updated 14 May 1993, of `The GNU Make Manual', for `make', Version 3.66 Beta. Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided also that the section entitled "GNU General Public License" is included exactly as in the original, and provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that the text of the translations of the section entitled "GNU General Public License" must be approved for accuracy by the Foundation. File: make.info, Node: Automatic, Next: Pattern Match, Prev: Pattern Examples, Up: Pattern Rules Automatic Variables ------------------- Suppose you are writing a pattern rule to compile a `.c' file into a `.o' file: how do you write the `cc' command so that it operates on the right source file name? You cannot write the name in the command, because the name is different each time the implicit rule is applied. What you do is use a special feature of `make', the "automatic variables". These variables have values computed afresh for each rule that is executed, based on the target and dependencies of the rule. In this example, you would use `$@' for the object file name and `$<' for the source file name. Here is a table of automatic variables: The file name of the target of the rule. If the target is an archive member, then `$@' is the name of the archive file. In a pattern rule that has multiple targets (*note Introduction to Pattern Rules: Pattern Intro.), `$@' is the name of whichever target caused the rule's commands to be run. The target member name, when the target is an archive member. *Note Archives::. For example, if the target is `foo.a(bar.o)' then `$%' is `bar.o' and `$@' is `foo.a'. `$%' is empty when the target is not an archive member. The name of the first dependency. If the target got its commands from an implicit rule, this will be the first dependency added by the implicit rule (*note Implicit Rules::.). The names of all the dependencies that are newer than the target, with spaces between them. For dependencies which are archive members, only the member named is used (*note Archives::.). The names of all the dependencies, with spaces between them. For dependencies which are archive members, only the member named is used (*note Archives::.). The stem with which an implicit rule matches (*note How Patterns Match: Pattern Match.). If the target is `dir/a.foo.b' and the target pattern is `a.%.b' then the stem is `dir/foo'. The stem is useful for constructing names of related files. In a static pattern rule, the stem is part of the file name that matched the `%' in the target pattern. In an explicit rule, there is no stem; so `$*' cannot be determined in that way. Instead, if the target name ends with a recognized suffix (*note Old-Fashioned Suffix Rules: Suffix Rules.), `$*' is set to the target name minus the suffix. For example, if the target name is `foo.c', then `$*' is set to `foo', since `.c' is a suffix. GNU `make' does this bizarre thing only for compatibility with other implementations of `make'. You should generally never use `$*' except in implicit rules or static pattern rules. If the target name in an explicit rule does not end with a recognized suffix, `$*' is set to the empty string for that rule. `$?' is useful even in explicit rules when you wish to operate on only the dependencies that have changed. For example, suppose that an archive named `lib' is supposed to contain copies of several object files. This rule copies just the changed object files into the archive: lib: foo.o bar.o lose.o win.o ar r lib $? Of the variables listed above, four have values that are single file names, and two have values that are lists of file names. These six have variants that get just the file's directory name or just the file name within the directory. The variant variables' names are formed by appending `D' or `F', respectively. These variants are semi-obsolete in GNU `make' since the functions `dir' and `notdir' can be used to get an equivalent effect (*note Functions for File Names: Filename Functions.). Here is a table of the variants: `$(@D)' The directory part of the file name of the target. If the value of `$@' is `dir/foo.o' then `$(@D)' is `dir/'. This value is `./' if `$@' does not contain a slash. `$(@D)' is equivalent to `$(dir $@)'. `$(@F)' The file-within-directory part of the file name of the target. If the value of `$@' is `dir/foo.o' then `$(@F)' is `foo.o'. `$(@F)' is equivalent to `$(notdir $@)'. `$(*D)' `$(*F)' The directory part and the file-within-directory part of the stem; `dir/' and `foo' in this example. `$(%D)' `$(%F)' The directory part and the file-within-directory part of the target archive member name. This makes sense only for archive member targets of the form `ARCHIVE(MEMBER)' and is useful only when MEMBER may contain a directory name. (*Note Archive Members as Targets: Archive Members.) `$( foo.1 will fail when the current directory is not the source directory, because `foo.man' and `sedscript' are not in the current directory. When using GNU `make', relying on `VPATH' to find the source file will work in the case where there is a single dependency file, since the `make' automatic variable `$<' will represent the source file wherever it is. (Many versions of `make' set `$<' only in implicit rules.) A makefile target like foo.o : bar.c $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o should instead be written as foo.o : bar.c $(CC) $(CFLAGS) $< -o $@ in order to allow `VPATH' to work correctly. When the target has multiple dependencies, using an explicit `$(srcdir)' is the easiest way to make the rule work well. For example, the target above for `foo.1' is best written as: foo.1 : foo.man sedscript sed -s $(srcdir)/sedscript $(srcdir)/foo.man > foo.1 File: make.info, Node: Utilities in Makefiles, Next: Standard Targets, Prev: Makefile Basics, Up: Makefile Conventions Utilities in Makefiles ====================== Write the Makefile commands (and any shell scripts, such as `configure') to run in `sh', not in `csh'. Don't use any special features of `ksh' or `bash'. The `configure' script and the Makefile rules for building and installation should not use any utilities directly except these: cat cmp cp echo egrep expr grep ln mkdir mv pwd rm rmdir sed test touch Stick to the generally supported options for these programs. For example, don't use `mkdir -p', convenient as it may be, because most systems don't support it. The Makefile rules for building and installation can also use compilers and related programs, but should do so via `make' variables so that the user can substitute alternatives. Here are some of the programs we mean: ar bison cc flex install ld lex make makeinfo ranlib texi2dvi yacc When you use `ranlib', you should test whether it exists, and run it only if it exists, so that the distribution will work on systems that don't have `ranlib'. If you use symbolic links, you should implement a fallback for systems that don't have symbolic links. It is ok to use other utilities in Makefile portions (or scripts) intended only for particular systems where you know those utilities to exist. File: make.info, Node: Standard Targets, Next: Command Variables, Prev: Utilities in Makefiles, Up: Makefile Conventions Standard Targets for Users ========================== All GNU programs should have the following targets in their Makefiles: `all' Compile the entire program. This should be the default target. This target need not rebuild any documentation files; info files should normally be included in the distribution, and DVI files should be made only when explicitly asked for. `install' Compile the program and copy the executables, libraries, and so on to the file names where they should reside for actual use. If there is a simple test to verify that a program is properly installed then run that test. Use `-' before any command for installing a man page, so that `make' will ignore any errors. This is in case there are systems that don't have the Unix man page documentation system installed. In the future, when we have a standard way of installing info files, `install' targets will be the proper place to do so. `uninstall' Delete all the installed files that the `install' target would create (but not the noninstalled files such as `make all' would create). `clean' Delete all files from the current directory that are normally created by building the program. Don't delete the files that record the configuration. Also preserve files that could be made by building, but normally aren't because the distribution comes with them. Delete `.dvi' files here if they are not part of the distribution. `distclean' Delete all files from the current directory that are created by configuring or building the program. If you have unpacked the source and built the program without creating any other files, `make distclean' should leave only the files that were in the distribution. `mostlyclean' Like `clean', but may refrain from deleting a few files that people normally don't want to recompile. For example, the `mostlyclean' target for GCC does not delete `libgcc.a', because recompiling it is rarely necessary and takes a lot of time. `realclean' Delete everything from the current directory that can be reconstructed with this Makefile. This typically includes everything deleted by distclean, plus more: C source files produced by Bison, tags tables, info files, and so on. One exception, however: `make realclean' should not delete `configure' even if `configure' can be remade using a rule in the Makefile. More generally, `make realclean' should not delete anything that needs to exist in order to run `configure' and then begin to build the program. `TAGS' Update a tags table for this program. `info' Generate any info files needed. The best way to write the rules is as follows: info: foo.info foo.info: $(srcdir)/foo.texi $(srcdir)/chap1.texi $(srcdir)/chap2.texi $(MAKEINFO) $(srcdir)/foo.texi You must define the variable `MAKEINFO' in the Makefile. It should run the Makeinfo program, which is part of the Texinfo2 distribution. `dvi' Generate DVI files for all TeXinfo documentation. For example: dvi: foo.dvi foo.dvi: $(srcdir)/foo.texi $(srcdir)/chap1.texi $(srcdir)/chap2.texi $(TEXI2DVI) $(srcdir)/foo.texi You must define the variable `TEXI2DVI' in the Makefile. It should run the program `texi2dvi', which is part of the Texinfo2 distribution. Alternatively, write just the dependencies, and allow GNU Make to provide the command. `dist' Create a distribution tar file for this program. The tar file should be set up so that the file names in the tar file start with a subdirectory name which is the name of the package it is a distribution for. This name can include the version number. For example, the distribution tar file of GCC version 1.40 unpacks into a subdirectory named `gcc-1.40'. The easiest way to do this is to create a subdirectory appropriately named, use `ln' or `cp' to install the proper files in it, and then `tar' that subdirectory. The `dist' target should explicitly depend on all non-source files that are in the distribution, to make sure they are up to date in the distribution. *Note Making Releases: (standards)Releases. `check' Perform self-tests (if any). The user must build the program before running the tests, but need not install the program; you should write the self-tests so that they work when the program is built but not installed. The following target is suggested as a conventional name, for programs in which it is useful. `installcheck' Perform installation tests (if any). The user must build and install the program before running the tests. You should not assume that `$(bindir)' is in the search path. `installdirs' It's useful to add a target named `installdirs' to create the directories where files are installed, and their parent directories. You can use a rule like this: # Make sure all installation directories, e.g. $(bindir) actually exist by # making them if necessary. installdirs: for file in $(bindir) $(datadir) $(libdir) $(infodir) $(mandir) ; do \ oIFS="$${IFS}"; IFS='/'; set - $${file}; IFS="$${oIFS}"; \ pathcomp=''; test ".$${1}" = "." && shift; \ while test $$# -ne 0 ; do \ pathcomp="$${pathcomp}/$${1}"; shift; \ if test ! -d "$${pathcomp}"; then \ echo "making directory $$pathcomp" 1>&2 ; \ mkdir "$${pathcomp}"; \ fi; \ done; \ done